package #(packageConfig.serviceImplPackage);

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.solon.service.impl.ServiceImpl;
import com.skiving.cloud.common.utils.PageParameter;
import #(packageConfig.entityPackage).#(table.buildEntityClassName());
import #(packageConfig.mapperPackage).#(table.buildMapperClassName());
#if(table.getGlobalConfig().isServiceGenerateEnable())
import #(packageConfig.servicePackage).#(table.buildServiceClassName());
#end
import org.noear.solon.annotation.Component;
import org.noear.solon.Utils;

/**
 * #(table.getComment()) 服务层实现。
 *
#if(javadocConfig.getAuthor())
 * @author #(javadocConfig.getAuthor())
#end
#if(javadocConfig.getSince())
 * @since #(javadocConfig.getSince())
#end
 */
@Component
public class #(table.buildServiceImplClassName()) extends ServiceImpl<#(table.buildMapperClassName()), #(table.buildEntityClassName())> #if(table.getGlobalConfig().isServiceGenerateEnable()) implements #(table.buildServiceClassName()) #end{
    /**
     * 分页查询#(table.getComment())
     *
     * @param parameter 查询参数
     * @return 分页查询结果
     */
    @Override
    public Page<#(table.buildEntityClassName())> queryByPage(PageParameter<#(table.buildEntityClassName())> parameter){
        Page<#(table.buildEntityClassName())> page = new Page<>(parameter.getPage(), parameter.getPageSize());
        QueryWrapper queryWrapper = QueryWrapper.create();
        if (parameter.getParam() != null) {
            //查询条件
            #for(column : table.columns)
                #if(column.propertySimpleType == "String")
            if (Utils.isNotBlank(parameter.getParam().#(column.getterMethod())())) {
                queryWrapper.and(#(table.buildEntityClassName())::#(column.getterMethod())).like(parameter.getParam().#(column.getterMethod())());
            }
                #end
            #end
        }
        return this.page(page, queryWrapper);
    }
}
